﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Petshop.Backend.Data
{
    class OrderRepository : Petshop.Backend.Data.IOrderRepository, IDisposable
    {
        private readonly IDatabaseSession _databaseSession;
        public OrderRepository(IDatabaseSession databaseSession)
        {
            _databaseSession = databaseSession;
        }
        public void Insert(Order order)
        {
            _databaseSession.Context.AddToOrders(order);
        }
        public void Save()
        {
            _databaseSession.Context.SaveChanges();
        }
        #region IDisposable
        private bool disposed = false;

        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                    _databaseSession.Context.Dispose();
                }
            }
            this.disposed = true;
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
        #endregion
    }
}
